package com.hongxun.design.ui.headandbottonpanel;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hongxun.design.R;
import com.hongxun.design.constant.Constant;


public class ImageText extends LinearLayout {
    private Context mContext = null;
    private ImageView mImageView = null;
    private TextView mTextView = null;
    private TextView button_num = null;//导航栏按钮显示的消息条数显示的textview
    private RelativeLayout iamge_button_num;//导航栏按钮显示的消息条数
    private final static int DEFAULT_IMAGE_WIDTH = 50;
    private final static int DEFAULT_IMAGE_HEIGHT = 50;
    private int CHECKED_COLOR = 0XFFF59100;
    private int UNCHECKED_COLOR = 0xff808080;
    private int BGCHECKED_COLOR = 0xFFF59100;
    private int BGUNCHECKED_COLOR = 0xFFFFFFFF;
    private RelativeLayout button_bg;

    public ImageText(Context context) {
        super(context);
        mContext = context;
    }

    public ImageText(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View parentView = inflater.inflate(R.layout.panel_bottom_button_item, this, true);
        button_bg = (RelativeLayout) findViewById(R.id.button_bg);
        mImageView = (ImageView) findViewById(R.id.image_iamge_text);
        mTextView = (TextView) findViewById(R.id.text_iamge_text);
        iamge_button_num = (RelativeLayout) findViewById(R.id.iamge_button_num);
        button_num = (TextView) findViewById(R.id.button_num);

    }

    public void setImage(int id) {
        if (mImageView != null) {
            mImageView.setImageResource(id);
            //setImageSize(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT);
        }

    }

    public void setText(String s) {
        if (mTextView != null) {
            mTextView.setText(s);
            mTextView.setTextColor(UNCHECKED_COLOR);
        }
    }

    public void setBackground() {
//		if(button_bg != null){
//			button_bg.setBackgroundColor(BGUNCHECKED_COLOR);
//		}
    }

    public void setButtonNum(int num) {

        if (iamge_button_num != null) {
            if (num == 0) {
                iamge_button_num.setVisibility(GONE);
            } else {
                iamge_button_num.setVisibility(VISIBLE);

            }

        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }

    private void setImageSize(int w, int h) {
        if (mImageView != null) {
            ViewGroup.LayoutParams params = mImageView.getLayoutParams();
            params.width = w;
            params.height = h;
            mImageView.setLayoutParams(params);
        }
    }

    public void setChecked(int itemID) {
        if (mTextView != null) {
            mTextView.setTextColor(CHECKED_COLOR);
        }
        int checkDrawableId = -1;
        switch (itemID) {
            case Constant.BTN_FLAG_MESSAGE:
                checkDrawableId = R.mipmap.home_checked;
                break;
            case Constant.BTN_FLAG_CONTACTS:
                checkDrawableId = R.mipmap.project_checked;
                break;
            case Constant.BTN_FLAG_NEWS:
                checkDrawableId = R.mipmap.encyclopedias_checked;
                break;
            case Constant.BTN_FLAG_SETTING:
                checkDrawableId = R.mipmap.my_checked;
                break;
            default:
                break;
        }
        if (mImageView != null) {
            mImageView.setImageResource(checkDrawableId);
        }
//		button_bg.setBackgroundColor(BGCHECKED_COLOR);
    }


}
